<?php

namespace App\Home\Controllers;

use App\Home\Filters\WorshipCollectionFilter;
use App\Home\Models\WorshipCollection;
use App\Home\Requests\WorshipCollectionRequest;
use App\Home\Resources\WorshipCollectionResource;
use Illuminate\Http\Request;

class WorshipCollectionController extends Controller
{
    public function store(
        WorshipCollectionRequest $request, 
        WorshipCollection $worshipCollection
    ){
        $inputs = $request->validated();
        $worshipCollection = $worshipCollection->add($inputs);

        return $this->created(WorshipCollectionResource::make($worshipCollection));
    }

    public function update(
        WorshipCollectionRequest $request, 
        WorshipCollection $worshipCollection
    ){
        $inputs = $request->validated();
        $worshipCollection->update($inputs);

        return $this->created(WorshipCollectionResource::make($worshipCollection));
    }

    public function destroy(
        WorshipCollection $worshipCollection
    ){
        $worshipCollection->delete();
        return $this->noContent();
    }

    public function index(
        WorshipCollectionRequest $request,
        WorshipCollectionFilter $filter
    ){
        $fields = [
            "*",
        ];
        $worshipCollections = WorshipCollection::query()
            ->filter($filter)
            ->select($fields)
            ->paginate();

        return $this->ok(WorshipCollectionResource::collection($worshipCollections));
    }

    public function show(
        Int $id
    ){
        $fields = [
            "*",
        ];
        $worshipCollection = WorshipCollection::query()
            ->select($fields)
            ->find($id);
        return $this->ok(WorshipCollectionResource::make($worshipCollection));
    }
}
